#!/bin/bash

prog="keystone-hotfix"
#plese also modify ver in .spec file
ver="0.0.1"

# create patch
rm -rf keystone_multiregion keystone.patch keystone.patch.0 ${prog}-${ver}
tar zxf keystone_multiregion.tgz
./patchall keystone_multiregion
if [ $? -ne 0 ]; then
    exit 1
fi

# create source
mkdir -p ${prog}-${ver}
cp -a \
 README \
 keystone.patch \
 ${prog}-${ver}/
tar zcvf ${prog}-${ver}.tar.gz  ${prog}-${ver}
if [ ! -f  ${prog}-${ver}.tar.gz ]; then
    echo "FATAL:  ${prog}-${ver}.tar.gz not found"
    exit 1
fi

if [ $# -eq 0 ];then
  echo "Usage: $0 -ba|-bp"
  exit
fi
HOME=/tmp/`whoami`
builddir=${HOME}/rpmbuild
specfile="${prog}.spec"

mkdir -p ${builddir}/SOURCES ${builddir}/SPECS
cp ${prog}-${ver}.tar.gz *.patch ${builddir}/SOURCES/

cp ${specfile} ${builddir}/SPECS/
cd ${builddir}/SPECS && rpmbuild ${1} ${specfile}

rm -rf keystone_multiregion keystone.patch keystone.patch.0 ${prog}-${ver}
